
{% extends "base.html" %} 
{% block head %}
<script src="/js/index.js" type="text/javascript"></script>
{% endblock %}
  
{% block content %}
    <h1>Your Test Results Info Below</h1>

    <div id="test_results"><h2>Test Results</h2></div>
    <div id="procedures"><h2>Procedures</h2></div>
 

    <hr>
        
    <div class="debug_bar">
   
       <b>DEBUG:</b> 
       <p> immunizations:{{ immunizations }}</p>
       <p> procedures:{{ procedures }}</p>
       <p> test_results:{{ test_results }}</p>
      
     <!--    -->
    </dir> 

    <script type="text/javascript" charset="utf-8">
    function reverseCompareToDate(a, b) {
      dateA = Date.parse(a.to);
      dateB = Date.parse(b.to);
      if (dateA < dateB) {return 1;} 
      if (dateA > dateB) {return -1;}
      if (dateA == dateB) {return 0;}
    }              
    function reverseCompareStartDate(a, b) {
      dateA = Date.parse(a.start_date);
      dateB = Date.parse(b.start_date);
      if (dateA < dateB) {return 1;} 
      if (dateA > dateB) {return -1;}
      if (dateA == dateB) {return 0;}
    }

    var current = $('<div>');
    current.append('<table >');
    var past = $('<div>');
    past.append('<table>');
    var c = {{ test_results }}.sort(reverseCompareToDate);
    for(var i in c) {
      var condition = c[i];
      cell_1 = condition.name+'  <span class="small">IDC9:'+condition.code+'</span> '; 
      cell_2 = '';
      if (condition.start_date) {cell_2 += '  '+condition.start_date; }
      if (condition.end_date) { cell_2 += ' to '+condition.end_date; }  

      if (condition.status.toLowerCase() == 'active') {
        current.append('<tr><td class="desc">'+cell_1+'</td><td class="date">'+cell_2+'</td></tr>');
      } else {
        past.append('<tr><td class="desc">'+cell_1+'</td><td class="date">'+cell_2+'</td></tr>');
      }
    }         
    current.append('</table>');
    current.append('</div>');
    past.append('</table>');
    past.append('</div>');
    
    $('#test_results').append('<h3>CURRENT RESULTS</h3>');
    $('#test_results').append(current);
    $('#test_results').append('<h3>PAST RESULTS</h3>');
    $('#test_results').append(past);

    
    </script>

{% endblock %} 


     
